/*    */ package com.services.bo;
/*    */ 
/*    */ import java.io.PrintStream;
/*    */ import java.io.StringReader;
/*    */ import javax.xml.parsers.DocumentBuilder;
/*    */ import javax.xml.parsers.DocumentBuilderFactory;
/*    */ import org.w3c.dom.CharacterData;
/*    */ import org.w3c.dom.Document;
/*    */ import org.w3c.dom.Element;
/*    */ import org.w3c.dom.Node;
/*    */ import org.w3c.dom.NodeList;
/*    */ import org.xml.sax.InputSource;
/*    */ 
/*    */ public class ParsingXML
/*    */ {
/*    */   private String statusCode;
/*    */   private String reasonIndonesia;
/*    */   private String reasonEnglish;
/*    */ 
/*    */   public void parse(String xmlRecords)
/*    */   {
/*    */     try
/*    */     {
/* 29 */       DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
/* 30 */       InputSource is = new InputSource();
/* 31 */       is.setCharacterStream(new StringReader(xmlRecords));
/*    */ 
/* 33 */       Document doc = db.parse(is);
/* 34 */       NodeList nodes = doc.getElementsByTagName("response");
/*    */ 
/* 36 */       for (int i = 0; i < nodes.getLength(); i++) {
/* 37 */         Element element = (Element)nodes.item(i);
/*    */ 
/* 39 */         NodeList name = element.getElementsByTagName("statuscode");
/* 40 */         Element line = (Element)name.item(0);
/* 41 */         setStatusCode(getCharacterDataFromElement(line));
/* 42 */         System.out.println("Status Code: " + getStatusCode());
/*    */ 
/* 44 */         NodeList indonesian = element.getElementsByTagName("reasonindonesia");
/* 45 */         line = (Element)indonesian.item(0);
/* 46 */         setReasonIndonesia(getCharacterDataFromElement(line));
/* 47 */         System.out.println("Reason Indonesia: " + getReasonIndonesia());
/*    */ 
/* 49 */         NodeList english = element.getElementsByTagName("reasonenglish");
/* 50 */         line = (Element)english.item(0);
/* 51 */         setReasonEnglish(getCharacterDataFromElement(line));
/* 52 */         System.out.println("Reason English: " + getReasonEnglish());
/*    */       }
/*    */     }
/*    */     catch (Exception ex)
/*    */     {
/* 57 */       System.out.println("parse()->Error: " + ex.getLocalizedMessage());
/*    */     }
/*    */   }
/*    */ 
/*    */   private String getCharacterDataFromElement(Element e) {
/* 62 */     Node child = e.getFirstChild();
/* 63 */     if ((child instanceof CharacterData)) {
/* 64 */       CharacterData cd = (CharacterData)child;
/* 65 */       return cd.getData();
/*    */     }
/* 67 */     return "";
/*    */   }
/*    */ 
/*    */   public void setStatusCode(String statusCode) {
/* 71 */     this.statusCode = statusCode;
/*    */   }
/*    */ 
/*    */   public String getStatusCode() {
/* 75 */     return this.statusCode;
/*    */   }
/*    */ 
/*    */   public void setReasonIndonesia(String reasonIndonesia) {
/* 79 */     this.reasonIndonesia = reasonIndonesia;
/*    */   }
/*    */ 
/*    */   public String getReasonIndonesia() {
/* 83 */     return this.reasonIndonesia;
/*    */   }
/*    */ 
/*    */   public void setReasonEnglish(String reasonEnglish)
/*    */   {
/* 90 */     this.reasonEnglish = reasonEnglish;
/*    */   }
/*    */ 
/*    */   public String getReasonEnglish()
/*    */   {
/* 97 */     return this.reasonEnglish;
/*    */   }
/*    */ }

/* Location:           F:\BCA.jar
 * Qualified Name:     com.services.bo.ParsingXML
 * JD-Core Version:    0.6.0
 */